package cn.wangjun.org.service.impl;

import cn.wangjun.basic.util.PageList;
import cn.wangjun.org.domain.Employee;
import cn.wangjun.org.mapper.EmployeeMapper;
import cn.wangjun.org.query.EmployeeQuery;
import cn.wangjun.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Transactional
    @Override
    public void add(Employee d) {
        employeeMapper.save(d);
    }
    @Transactional
    @Override
    public void upadte(Employee d) {
        employeeMapper.update(d);
    }
    @Transactional
    @Override
    public void del(Long id) {
        employeeMapper.remove(id);
    }

    @Override
    public Employee getById(Long id) {
        return employeeMapper.loadById(id);
    }

    @Override
    public List<Employee> getAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public PageList<Employee> queryData(EmployeeQuery query) {
        //获取的总条数
        Long totals = employeeMapper.queryCount(query);
        //每页数据
        List<Employee> list = employeeMapper.queryData(query);

        return new PageList<>(totals,list);
    }

    @Override
    public void patchDelete(List<Long> ids) {
        employeeMapper.patchDelete(ids);
    }
}
